<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>会员登录</title>

    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"/>
    <script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
    <script src="js/jquery.validate.min.js" type="text/javascript"></script>
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
    <!-- 引入自定义css文件 style.css -->

    <style>
        body {
            margin-top: 20px;
            margin: 0 auto;
        }

        .carousel-inner .item img {
            width: 100%;
            height: 300px;
        }

        .container .row div {
            /* position:relative;
                         float:left; */

        }

        font {
            color: #666;
            font-size: 22px;
            font-weight: normal;
            padding-right: 17px;
        }
        .error{
            color:red;
        }
    </style>
    <script type="text/javascript">
        function changeImage() {
            var image = document.getElementById("image");
            var rundomCode = Math.random();
            image.src = "${pageContext.request.contextPath}/checkImg?hh=" + rundomCode + "";
        }

        //自定义校验规则验证码
        $.validator.addMethod(
            //规则的名称
            "checkCode",
            //校验的函数
            function(value,element,params){
                /* alert(value);
                alert(params); */
                //定义一个标志
                var flag = false;
                //value:输入的内容
                //element:被校验的元素对象
                //params：规则对应的参数值
                //目的：对输入的username进行ajax校验
                $.ajax({
                    "async":false,
                    "url":"${pageContext.request.contextPath}/checkCode",
                    "data":{"checkCode":value},
                    "type":"POST",
                    "dataType":"json",
                    "success":function(data){
                        flag = data.isExist;
                    }
                });


                //返回false代表该校验器不通过
                return flag;
            }

        );

        $(function(){
            $("#loginForm").validate({
                rules:{
                    "checkCode":{
                        "checkCode":true
                    }
                },

                messages:{
                    "checkCode":{
                        "checkCode":"验证码错误"
                    }
                }
            });



        });
    </script>
</head>
<body>

<!-- 引入header.jsp -->
<jsp:include page="/header.jsp"></jsp:include>


<div class="container"
     style="width: 100%; height: 460px; background: #FF2C4C url('images/loginbg.jpg') no-repeat;">
    <div class="row">
        <div class="col-md-7">
            <%--<img src="./image/login.jpg" width="500" height="330" alt="会员登录" title="会员登录">--%>
        </div>

        <div class="col-md-5">
            <div
                    style="width: 440px; border: 1px solid #E7E7E7; padding: 20px 0 20px 30px; border-radius: 5px; margin-top: 60px; background: #fff;">
                <font>会员登录</font>USER LOGIN
                <c:if test="${empty loginFall}">
                    <div>&nbsp;</div>
                </c:if>
                <c:if test="${!empty loginError}">
                    <div><font style="color: red;font-size:2px">用户名或者密码错误</font></div>
                </c:if>
                <form class="form-horizontal" id="loginForm" action="${pageContext.request.contextPath}/login" method="post">
                    <div class="form-group">
                        <label for="username" class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="username" name="username"
                                   placeholder="请输入用户名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-6">
                            <input type="password" class="form-control" id="inputPassword3" name="password"
                                   placeholder="请输入密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">验证码</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="inputVC"
                                   placeholder="请输入验证码" name="checkCode">
                        </div>
                        <div class="col-sm-2" style="width: 140px">
                            <img src="${pageContext.request.contextPath}/checkImg" id="image"/><br>
                            <a href="javascript:void(0)" onclick="changeImage()"
                               style="font-size: 1px; text-decoration: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;看不清，换一张</a>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <div class="checkbox">
                                <label> <input type="checkbox" name="autoLogin"> 自动登录
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label> <input
                                    type="checkbox"> 记住用户名
                            </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <input type="submit" width="100" value="登录" name="submit"
                                   style="background: url('./images/login.gif') no-repeat scroll 0 0 rgba(0, 0, 0, 0); height: 35px; width: 100px; color: white;">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 引入footer.jsp -->
<jsp:include page="/footer.jsp"></jsp:include>

</body>
</html>